<?php

namespace app\api\middleware;

use think\facade\Cache;

class Auth
{
    public function handle($request, \Closure $next)
    {
        $token = request()->header('Authorization');
        $request->auth = Cache::has(config('cache.redis.prefix') . $token);
        if ($request->auth) {
            $info = Cache::get(config('cache.redis.prefix') . $token);
            $request->uid = $info['id'];
        } else {
            $request->uid = 0;
        }

        $response = $next($request);
        return $response;
    }

    public function end(\think\Response $response)
    {
    }
}
